package cn.edu.sdjzu.xg11.dao;

import java.util.Collection;
import java.util.TreeSet;

import org.springframework.stereotype.Repository;

import cn.edu.sdjzu.xg11.domain.School;
@Repository
public final class SchoolDao {
	private static Collection<School> schools;
	static{
		schools = new TreeSet<School>();
		School school = new School(1,"土木工程","01","");
		schools.add(school);
		schools.add(new School(2,"管理工程","02",""));
		schools.add(new School(3,"市政工程","03",""));
		schools.add(new School(4,"艺术","04",""));
	}
	/* (non-Javadoc)
	 * @see cn.edu.sdjzu.xg11.dao.impl.SchoolDao#getSchools()
	 */
	public Collection<School> getSchools(){
		return SchoolDao.schools;
	}
	
	/* (non-Javadoc)
	 * @see cn.edu.sdjzu.xg11.dao.impl.SchoolDao#getSchool(java.lang.Integer)
	 */
	public School getSchool(Integer id){
		School desiredSchool = null;
		for (School school : schools) {
			if(id.equals(school.getId())){
				desiredSchool =  school; 
			}
		}
		return desiredSchool;
	}
	
	/* (non-Javadoc)
	 * @see cn.edu.sdjzu.xg11.dao.impl.SchoolDao#updateSchool(cn.edu.sdjzu.xg11.domain.School)
	 */
	public boolean updateSchool(School school){
		schools.remove(school);
		return schools.add(school);		
	}
	
	/* (non-Javadoc)
	 * @see cn.edu.sdjzu.xg11.dao.impl.SchoolDao#addSchool(cn.edu.sdjzu.xg11.domain.School)
	 */
	public boolean addSchool(School school){
		return schools.add(school);		
	}

	/* (non-Javadoc)
	 * @see cn.edu.sdjzu.xg11.dao.impl.SchoolDao#deleteSchool(java.lang.Integer)
	 */
	public boolean deleteSchool(Integer id){
		School school = this.getSchool(id);
		return this.deleteSchool(school);
	}
	
	/* (non-Javadoc)
	 * @see cn.edu.sdjzu.xg11.dao.impl.SchoolDao#deleteSchool(cn.edu.sdjzu.xg11.domain.School)
	 */
	public boolean deleteSchool(School school){
		return schools.remove(school);
	}
	
	
	public static void main(String[] args){
		
	}

	private static void display(Collection<School> schools) {
		for (School school : schools) {
			System.out.println(school);
		}
	}
	
	
}
